home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / SAMDU240.ZIP / SAMPLE.C < prev    next >
Text File  |  1993-10-01  |  25KB  |  588 lines

  1. #include <Windows.h>
  2.  
  3. #include <IO.h>
  4. #include <StdIO.h>
  5. #include <StdLib.h>
  6. #include <String.h>
  7.  
  8. #include "DDrive.h"
  9. #include "DiskDriv.h"
  10. #include "HandleSt.h"
  11. #include "IOStatus.h"
  12. #include "Sample.h"
  13.  
  14. #ifdef DEBUG
  15. #include "DebugOut.h"
  16. #endif
  17.  
  18. BOOL bCancel ;
  19. BOOL bFast ;
  20. BOOL bIdle ;
  21. BOOL bQuick ;
  22. BOOL bRegisteredClass ;
  23.  
  24. char czIconMessage[64] ;
  25. char czNormalMessage[512] ;
  26.  
  27. FARPROC lpfnHandleStatus ;
  28.  
  29. HINSTANCE hInstance ;
  30.  
  31. HWND hWnd ;
  32.  
  33. UINT nNumberOfDrives ;
  34. UINT nFormatOption ;
  35. UINT nPercentageToColor ;
  36.  
  37. VOID far * pCDebugOut ;
  38.  
  39. VOID far * pCVDriveTest ;
  40.  
  41. VOID far *pCVDrives[26] ;
  42.  
  43. VOID far * pCDiskImage ;
  44.  
  45. VOID far * pCDiskTemporary ;
  46.  
  47. #pragma warning(disable:4100)
  48. int PASCAL WinMain ( HINSTANCE hCurrentInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, UINT nCmdShow)
  49. {
  50.     MSG msg;
  51.  
  52.     UINT n ;
  53.  
  54. #ifdef DEBUG
  55.     pCDebugOut = DebugOutCreate ( lpCmdLine ) ;
  56. #endif
  57.  
  58.     bRegisteredClass = FALSE ;
  59.     if (!hPrevInstance)
  60.        {
  61.        if (!InitApplication(hCurrentInstance)) return (FALSE);
  62.        bRegisteredClass = TRUE ;
  63.        }
  64.  
  65.     if (!InitInstance(hCurrentInstance, nCmdShow)) return (FALSE);
  66.  
  67.     hInstance = hCurrentInstance ;
  68.  
  69.     while (GetMessage(&msg, NULL, NULL, NULL))
  70.        {
  71.        TranslateMessage(&msg);
  72.        DispatchMessage(&msg);
  73.        }
  74.  
  75.     if ( nNumberOfDrives )
  76.        {
  77.        for ( n=0; n<nNumberOfDrives; n++ ) DDriveDelete ( pCVDrives[n] ) ;
  78.        }
  79.  
  80.     if ( bRegisteredClass ) UnregisterClass ( "SampleWClass", hInstance ) ;
  81.  
  82.     return ( msg.wParam ) ;
  83. }                            
  84. #pragma warning(default:4100)
  85.  
  86. BOOL InitApplication ( HINSTANCE hInstance )
  87. {
  88.     WNDCLASS  wc;
  89.  
  90.     wc.style = NULL;
  91.     wc.lpfnWndProc = MainWndProc;
  92.     wc.cbClsExtra = 0;
  93.     wc.cbWndExtra = 0;
  94.     wc.hInstance = hInstance;
  95.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  96.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  97.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  98.     wc.lpszMenuName =  "SampleMenu";
  99.     wc.lpszClassName = "SampleWClass";
  100.     return (RegisterClass(&wc));
  101. }
  102.  
  103. BOOL InitInstance ( HINSTANCE hInstance, UINT nCmdShow )
  104. {
  105.  
  106.     char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  107.     char czBuffer[256] ;
  108.  
  109.     HMENU hMainMenu ;
  110.     HMENU hPopupMenu ;
  111.  
  112.     int i ;
  113.  
  114.     UINT nMenuID ;
  115.     UINT nPopupMenuID ;
  116.  
  117.     VOID far * pCVDriveTest ;
  118.  
  119.     hWnd = CreateWindow( "SampleWClass", "Sample SABDU001.DLL Application", WS_OVERLAPPEDWINDOW,
  120.                          100, 200, 400, 200,
  121.                          NULL, NULL, hInstance, NULL );
  122.     if (!hWnd) return (FALSE);
  123.  
  124. #ifdef DEBUG
  125.     /* The following will be executed if the program is invoked with /D1 on the command line   */
  126.     /* It will be written to a trace file unless /M1 is also on the command line in which case */
  127.     /* it will be displayed in a MessageBox on the screen                                      */
  128.     wsprintf ( DebugOutczDebugBuffer(), "This is a sample of a debug trace.\n hWnd = %4.4X", hWnd ) ;
  129.     DebugOutOutputIf ( 0x00000001L, DebugOutczDebugBuffer(), "Sample Trace", MB_OK ) ;
  130. #endif
  131.  
  132.     nMenuID = 0 ;
  133.     nNumberOfDrives = 0 ;
  134.     hMainMenu = GetMenu ( hWnd ) ;
  135.     for ( i = 0; i < sizeof(alphabet)/sizeof(alphabet[0])-1 ; i++ )
  136.        {
  137.        pCVDriveTest = (VOID far *) DDriveCreate ( alphabet[i], (lpfnHANDLESTATUS) lpfnHandleStatus ) ;
  138.        if (pCVDriveTest==NULL)
  139.           {
  140.           ; /* Memory problems or worse */
  141.           return ( FALSE ) ;
  142.           break ;
  143.           }
  144.        if ((VDriveIsUseable ( pCVDriveTest ))&&(!VDriveIsRemote ( pCVDriveTest ))&&(VDriveIsRemovable ( pCVDriveTest )))
  145.           {
  146.           pCVDrives[nNumberOfDrives] = pCVDriveTest ;
  147.           nNumberOfDrives++ ;
  148.           nMenuID += 100 ;
  149.           hPopupMenu = CreatePopupMenu () ;
  150.           nPopupMenuID = nMenuID ;
  151.           AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Compare" ) ;
  152.           nPopupMenuID++ ;
  153.           if ( FD0360 & VDriveType  ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 0&360KB" ) ;
  154.           nPopupMenuID++ ;
  155.           if ( FD0720 & VDriveType  ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 0&720KB" ) ;
  156.           nPopupMenuID++ ;
  157.           if ( FD1200H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 1&200KB" ) ;
  158.           nPopupMenuID++ ;
  159.           if ( FD1440H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 1&440KB" ) ;
  160.           nPopupMenuID++ ;
  161.           if ( FD2880H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 2&880KB" ) ;
  162.           AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Read" ) ;
  163.           AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Write" ) ;
  164.           czBuffer[0] = '&' ;
  165.           czBuffer[1] = VDriveLetter ( pCVDriveTest ) ;
  166.           czBuffer[2] = ':' ;
  167.           czBuffer[3] = '\0' ;
  168.           AppendMenu ( hMainMenu, MF_ENABLED|MF_STRING|MF_POPUP, hPopupMenu, czBuffer ) ;
  169.           }
  170.        else
  171.           {
  172.           DDriveDelete ( pCVDriveTest ) ;
  173.           }
  174.        }
  175.  
  176.     if ( !nNumberOfDrives ) return ( FALSE ) ;
  177.  
  178.     bCancel = FALSE ;
  179.     bFast   = FALSE ;
  180.     bIdle   = TRUE ;
  181.     bQuick  = FALSE ;
  182.  
  183.     pCDiskImage = NULL ;
  184.  
  185.     lpfnHandleStatus = MakeProcInstance ( (FARPROC)HandleStatus, hInstance ) ;
  186.  
  187.     (*(lpfnHANDLESTATUS)lpfnHandleStatus) ( STATUS1_INIT, 0, (UINT)hWnd, (UINT)hInstance, MAKELONG ( TIMER_INTERVAL, 0x0000 ), MAKELONG ( 0x0001, 0x0001 ) ) ;
  188.  
  189.     ShowWindow( hWnd, nCmdShow ) ;
  190.     UpdateWindow( hWnd ) ;
  191.     return ( TRUE ) ;
  192.  
  193. }
  194.  
  195. long FAR PASCAL MainWndProc ( HWND hWnd, UINT nMessage, UINT nParam, LONG lParam )
  196. {
  197.     char  czMessageBuffer[512] ;
  198.  
  199.     HDC     hdc ;
  200.  
  201.     PAINTSTRUCT ps ;
  202.  
  203.     RECT    rClient ;
  204.  
  205.     STMESSAGE far *lpstMessage ;
  206.  
  207.     UINT nAction ;
  208.     UINT nDrive ;
  209.  
  210.     char czApplicationTitle [] = "SAB Diskette Utility" ;
  211.     char czFileName [] = "SABDU.SDU" ;
  212.     char czVersionNumber [] = "2.00" ;
  213.     char czFullPath [_MAX_PATH] ;
  214.  
  215.     switch ( nMessage )
  216.        {
  217.        case WM_PAINT:
  218.           {
  219.           hdc = BeginPaint ( hWnd, &ps ) ;
  220.  
  221.           if (!IsIconic( hWnd ))
  222.              {
  223.              GetClientRect ( hWnd, &rClient ) ;
  224.              if (bIdle)
  225.                 {
  226.                 _fstrcpy ( czMessageBuffer, "Please select an item from the menu" ) ;
  227.                 }
  228.              else
  229.                 {
  230.                 _fstrcpy ( czMessageBuffer, czNormalMessage ) ;
  231.                 }
  232.              DrawText ( hdc, czMessageBuffer, -1, &rClient, DT_CENTER|DT_WORDBREAK ) ;
  233.              }
  234.  
  235.           EndPaint ( hWnd, &ps ) ;
  236.           return ( FALSE ) ;
  237.           break ;
  238.           }
  239.        case USR_ACTIVE:
  240.           {
  241.           bIdle = FALSE ;
  242.  
  243.           lpstMessage = (STMESSAGE far *)lParam ;
  244.  
  245.           if (lpstMessage->pIconMessage)   _fstrcpy ( czIconMessage, lpstMessage->pIconMessage   )  ;
  246.           if (lpstMessage->pNormalMessage) _fstrcpy ( czNormalMessage, lpstMessage->pNormalMessage ) ;
  247.           nPercentageToColor = lpstMessage->nPercentageToColor ;
  248.  
  249.           InvalidateRect ( hWnd, NULL, TRUE ) ;
  250.           UpdateWindow ( hWnd ) ;
  251.  
  252.           return ( !bCancel ) ;
  253.           break ;
  254.           }
  255.        case USR_UPDATE:
  256.           {
  257.           bIdle = FALSE ;
  258.  
  259.           lpstMessage = (STMESSAGE far *)lParam ;
  260.  
  261.           if (lpstMessage->pIconMessage)   _fstrcpy ( czIconMessage, lpstMessage->pIconMessage   )  ;
  262.           if (lpstMessage->pNormalMessage) _fstrcpy ( czNormalMessage, lpstMessage->pNormalMessage ) ;
  263.           nPercentageToColor = lpstMessage->nPercentageToColor ;
  264.  
  265.           InvalidateRect ( hWnd, NULL, FALSE ) ;
  266.           UpdateWindow ( hWnd ) ;
  267.  
  268.           return ( !bCancel ) ;
  269.           break ;
  270.           }
  271.        case USR_INACTIVE:
  272.           {
  273.           bIdle = TRUE ;
  274.           InvalidateRect ( hWn